package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.exception.PHException;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantOpenaccountbankService;
import com.ph.irp.model.PBaseAssistantmaterialOpenaccountbank;

public class AccountbankAction extends ActionSupport{
	//出纳管理及开户行service
	private PBaseAssistantOpenaccountbankService accountBankService ;
	//账户管理及开户行list
	private List<PBaseAssistantmaterialOpenaccountbank>  accountbankList ;
	//账户管理及开户行model
	private PBaseAssistantmaterialOpenaccountbank accountbankModel ; 
	
	//接收选中复选框传递的数据
	private Object[] rowlist = null ;
	
	//定位视图
	private String FORWORD ;
	public String showAccountbanks() throws Throwable{

		accountbankList = accountBankService.getAllAccountBanks(accountbankModel);		
		accountbankModel = null ;
		
		FORWORD = "success";
		return FORWORD;
	}
	
	/**
	 * action默认执行的方法
	 */
	public String execute() throws Exception{
				
		try {
			return this.showAccountbanks();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			throw new Exception(e.getMessage());
		}
		
	}
	/**
	 * 新增出纳管理及开户行
	 * @return
	 * @throws PHException
	 */
	public String addAccountbank()throws Throwable{
		//如果accountbankModel不为null，新增
		if(accountbankModel!=null){
			
			accountBankService.addAccountBank(accountbankModel) ;
			
		}
		FORWORD = "success";	
		
		return FORWORD ;
		
	}
	
	public String editAccountbank()throws Throwable{
		
		//如果accountbankModel不为null，修改
		if(accountbankModel!=null){
			
			accountBankService.updateAccountBank(accountbankModel) ;
			
		}
		//定位视图到list页面
		FORWORD="success";
		return FORWORD ;
	}
	/**
	 * 更新出纳管理及开户行
	 * @return
	 * @throws PHException
	 */
	public String updateAccountbank()throws Throwable{
		
		int accountbankId = Integer.valueOf((String) rowlist[0]) ;	
//		//
//		for(PBaseAssistantmaterialOpenaccountbank accountbank:accountbankList){
//			if(accountbank.getOpenAccountBankId()==accountbankId){
//				accountbankModel = accountbank ;
//			}
//		}
		
		accountbankModel = accountBankService.getAccountBankById(accountbankId) ;
		FORWORD="success";
		return FORWORD ;
	}
	
	/**
	 * 将视图定位到新增界面
	 * @return
	 */
	public String addInputAccountbank()throws Throwable{
		FORWORD="success";
		return FORWORD ;
	}
	
	/**
	 * 删除辅助物料出纳管理及开户行
	 * @return
	 */
	public String deleteAccountbank()throws Throwable{
		
		//批量删除出纳管理及开户行
		accountBankService.deleteAccountBankById(rowlist);
		FORWORD="success";			
		return FORWORD ;
	}
	
	/**
	 * 选择辅助物料出纳管理及开户行
	 * @return
	 */
	public String selectAccountbank()throws Throwable{
		
		accountbankList = accountBankService.getAllAccountBanks(accountbankModel);
		FORWORD="success";
		return FORWORD ;
	}

	/**
	 * getters and setters for instance variables
	 * @return
	 */
	public Object[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}

	public PBaseAssistantOpenaccountbankService getAccountBankService() {
		return accountBankService;
	}

	public void setAccountBankService(
			PBaseAssistantOpenaccountbankService accountBankService) {
		this.accountBankService = accountBankService;
	}

	public List<PBaseAssistantmaterialOpenaccountbank> getAccountbankList() {
		return accountbankList;
	}

	public void setAccountbankList(
			List<PBaseAssistantmaterialOpenaccountbank> accountbankList) {
		this.accountbankList = accountbankList;
	}

	public PBaseAssistantmaterialOpenaccountbank getAccountbankModel() {
		return accountbankModel;
	}

	public void setAccountbankModel(
			PBaseAssistantmaterialOpenaccountbank accountbankModel) {
		this.accountbankModel = accountbankModel;
	}
 
}
